package com.xingli.jingdongshop.proto;

import com.google.protobuf.InvalidProtocolBufferException;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class Test {
    //protoc --java_out=./zhu ./GoodsSlot.proto
    public static void main(String[] args) throws IOException {
//        PersonProtosProtos.GoodsSlot.Builder personBuilder = PersonProtosProtos.GoodsSlot.newBuilder();
//        personBuilder.setGoodsId(1);
//        personBuilder.setGoodsName("21321");
//
//
//        PersonProtosProtos.GoodsSlot person = personBuilder.build();
//        person.getGoodsName();
//
//        byte[] data = person.toByteArray();//获取字节数组，适用于SOCKET或者保存在磁盘。
//反序列化
        FileInputStream fileInputStream = new FileInputStream("E:\\dev\\wx-box-back\\s-application\\src\\main\\java\\com\\xingli\\application\\proto\\zhuzhuz");
        byte[] bytes = new byte[9];
        int length = 0;
        if ((length = fileInputStream.read(bytes)) != -1) {
            PersonProtosProtos.GoodsSlot result = PersonProtosProtos.GoodsSlot.parseFrom(bytes);
            System.out.println(result.getGoodsName());
        }

    }
}
